#define _CRT_SECURE_NO_WARNINGS 1

#include <iostream>
#include <vector>

using namespace std;

class Solution
{
public:
    int minOperations(vector<int>& nums, int x)
    {
        int n = nums.size(), left = 0, right = 0, sum = 0, len = -1, target = 0;
        for (auto& e : nums)
        {
            target += e;
        }
        target = target - x;
        while (right < n)
        {
            sum += nums[right++];
            while (sum > target && left < right)
            {
                sum -= nums[left++];
            }
            if (sum == target)
            {
                len = max(len, right - left);
            }
        }
        return n - len;
    }
};

void test()
{
    Solution s;
    vector<int> nums = { 3,2,20,1,1,3 };
    cout << s.minOperations(nums, 10) << endl;
}

int main()
{
	test();
	return 0;
}